<template>
    <div>
        <h1 style="text-align:center;">Salary Management Details</h1>
        <el-table :data="tableData" border style="width: 100%"> 
            <el-table-column prop="year" label="year" align="center"></el-table-column>
            <el-table-column prop="month" label="month" align="center"></el-table-column>
            <el-table-column prop="realName" label="realName" align="center"></el-table-column>
            <el-table-column prop="basicSalary" label="basicSalary" align="center"></el-table-column>
            <el-table-column prop="postSalary" label="postSalary" align="center"></el-table-column>
            <el-table-column prop="mealSalary" label="mealSalary" align="center"></el-table-column>
            <el-table-column prop="travelSalary" label="travelSalary" align="center"></el-table-column>
            <el-table-column prop="overtimeSalary" label="overtimeSalary" align="center"></el-table-column>
            <el-table-column prop="netSalary" label="netSalary" align="center"></el-table-column>
            <el-table-column prop="status" label="status" align="center">
                <template slot-scope="scope">
                    <el-button v-if="scope.row.status == 0" type="text" size="small" @click="confirmSalary(scope.row.id)">confirm</el-button>
                    <el-tag v-if="scope.row.status == 1" type="success">Confirmed salary</el-tag>
                </template>
            </el-table-column>
        </el-table>
        <el-pagination
        @size-change="sizeChangeHandle"
        @current-change="currentChangeHandle"
        :current-page="pageIndex"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="pageSize"
        :total="totalPage"
        layout="total, sizes, prev, pager, next, jumper">
        </el-pagination>
    </div>
</template>

<script>
  export default {
    data () {
      return {
        tableData: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        year: '',
        month: ''
      }
    },
    activated () {
      this.querySalary()
    },
    methods: {
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.querySalary()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.querySalary()
      },
      // 获取登录的教师信息
      querySalary () {
        this.$http({
          url: this.$http.adornUrl('/edu/tedusalary/querySalaryPage'),
          method: 'get',
          params: this.$http.adornParams({
            'page': this.pageIndex,
            'limit': this.pageSize
          })
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.tableData = data.data.list
            this.totalPage = data.data.total
          } else {
            this.tableData = []
            this.totalPage = 0
          }
        })
      },
      // 确认薪资
      confirmSalary (id) {
        this.$http({
          url: this.$http.adornUrl('/edu/tedusalary/confirmSalary/' + id),
          method: 'post'
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.$message.success('Confirmation succeeded')
            this.querySalary()
          } else {
            this.$message.error(data.msg)
          }
        })
      }
    }
  }
</script>
